package com.etao.tools.common;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * Created by lyp on 2016/8/8.
 */
public class PropertyUtils {
    private static final Properties prop = new Properties();
    static {
        String fileName="common.properties";//这里是指放在classes下，如果有包的话，前面加包名即可。例：/com/web/db.properties
        InputStream inputStream = null;
        try {
            //从当前类目录中读配置文件
            inputStream = PropertyUtils.class.getClassLoader().getResourceAsStream(fileName);
            //从绝对路径中读取配置文件
            //inputStream = new FileInputStream("D:");
            prop.load(new InputStreamReader(inputStream, "UTF-8"));
            inputStream.close();
        } catch (Exception ex) {
            throw new RuntimeException(ex.getMessage());
        }
    }

    public static String getProperty(String key, String defaultValue) {
        return prop.getProperty(key, defaultValue);
    }

    public static String getProperty(String key) {
        return prop.getProperty(key);
    }
}
